package com.samebuilding.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.samebuilding.domain.ActivityBigtype;
import com.samebuilding.service.ActivityTypeService;

public class AddBigTypeAction extends Action {

	
	private ActivityTypeService activityTypeService;
	
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		
		String method = request.getMethod().toUpperCase();
		
		
		if(method.equals("GET")) {
			
			return mapping.findForward("addBigType");
		} else if(method.equals("POST")) {
			DynaActionForm bigTypeForm = (DynaActionForm)form;
			
			ActivityBigtype bigType = new ActivityBigtype((String)bigTypeForm.get("bigType"));
			
			this.activityTypeService.addActivityBigType(bigType);
			
			return mapping.findForward("success");
		}
		
		return mapping.findForward("failed");
	}


	public ActivityTypeService getActivityTypeService() {
		return activityTypeService;
	}


	public void setActivityTypeService(ActivityTypeService activityTypeService) {
		this.activityTypeService = activityTypeService;
	}
	
}
